/*
 * @LastEditTime: 2023-02-28 14:36:34
 */
import { router } from "../index";
import { Musics } from "../../Models/Musics.schema";
import { MusicsController } from "../../Controller/Musics.controller";
import { createMusicsDTO, updateMusicsDTO } from "../../DTO/Musics.dto";

const MusicsModel = new MusicsController(Musics);


//按歌曲集名获取歌曲集
router.get("/theMusics", async (ctx, next) => {
  if (ctx.request.query.id) {
    ctx.body = await MusicsModel.findById(ctx.request.query.id.toString());
  }
});

//获取全部歌曲集
router.get("/theMusics/:all", async (ctx, next) => {
  ctx.body = await MusicsModel.findAll();
});

// 创建歌曲集
router.post('/theMusics', async (ctx, next) => {
  ctx.body = await MusicsModel.createItem(ctx.request.body as createMusicsDTO);
});


//删除歌曲集
router.delete("/theMusics/:id", async (ctx, next) => {
  console.log(ctx.params.id);
  ctx.body = await MusicsModel.removeById(ctx.params.id);
});

// 更新歌曲集
router.patch("/theMusics/:id", async (ctx, next) => {
  if(ctx.params.id)
  ctx.body = await MusicsModel.updateById(
    ctx.params.id,
    ctx.request.body as updateMusicsDTO
  );
});